import os
import sys
project_root = os.path.abspath(os.path.join(os.path.dirname(__file__), '..'))
if project_root not in sys.path:
    sys.path.append(project_root)
    
from readlater.database.db_manager import DatabaseManager
from readlater.config.config_manager import ConfigManager
from readlater.chatlog import ChatlogManager
from readlater.utils.logger import get_logger


# 启动服务
if __name__ == "__main__":
    logger = get_logger(__name__)
    logger.info("启动服务")

    # 初始化数据库
    config_manager = ConfigManager()
    chatlog_manager = ChatlogManager()
    # 从数据库中获取所有文章
    articles = chatlog_manager.read_articles(config_manager.get("wechat.target_user"))

    for article in articles:
        logger.info(f"文章标题: {article.get('title')}")

    logger.info(f"共获取到 {len(articles)} 篇文章")

    logger.info("开始保存文章")
    if chatlog_manager.save_articles(articles):
        logger.error("保存成功")
    else:
        logger.error("保存失败")




